﻿Imports System.Text
Imports SCS.DataAccess
Imports SCS.BusinessEntities
<TestClass()>
Public Class AlumnoTest

    <TestMethod()>
    Public Sub CRUDAlumno()
        Dim ar As IAlumnosRepositorio =
            New AlumnosRepositorio
        Dim al = New Alumno
        al.id = Guid.NewGuid()
        al.nombre = "juan"
        al.edad = 5
        ar.Add(al)
        Dim target = ar.GetOne(al.id)
        Assert.IsNotNull(target)
        al.nombre = "change"
        ar.Update(al)
        target = ar.GetOne(al.id)
        Assert.AreEqual(Of String)("change", target.nombre)
        ar.Delete(al)
        target = ar.GetOne(al.id)
        Assert.IsNull(target)
    End Sub
    <TestMethod()> _
    Public Sub ADODESCTest()
        Dim ar As IAlumnosRepositorio =
            New AlumnosRepositorio
        Dim ds = ar.GetData()

        Dim r = ds.NewRow()
        r(0) = Guid.NewGuid
        r(1) = "test"
        r(2) = 5
        ds.Rows.Add(r)
        ar.SaveData(ds)

        Dim target = ar.GetData()
        Dim rtarget = target.Select("Id='" + r("Id").ToString() + "'").SingleOrDefault
        Assert.IsNotNull(rtarget)

        r(1) = "change"

        ar.SaveData(ds)

        target = ar.GetData()
        rtarget = target.Select("Id='" + r("Id").ToString() + "'").SingleOrDefault

        Assert.AreEqual(Of String)("change", rtarget(1))

        r.Delete()

        ar.SaveData(ds)

        Try
            target = ar.GetData()
            rtarget = target.Select("Id='" + r("Id").ToString() + "'").SingleOrDefault
            Assert.Fail("Delete unsuccess")
        Catch ex As Exception

        End Try

    End Sub

End Class
